home *** CD-ROM | disk | FTP | other *** search
- /*
- File: 2020HalfGateway.h
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __2020HALFGATEWAY__
- #define __2020HALFGATEWAY__
-
- #ifndef __2020LETTER__
- #include "2020Letter.h"
- #endif
-
- #ifndef __2020HALFGATEWAYMISC__
- #include "2020HalfGatewayMisc.h"
- #endif
-
- #ifndef __AOCEHGWYTYPES__
- #include "AOCEHalfGatewayTypes.h"
- #endif
-
- #ifndef __COREGATEWAYTYPES__
- #include "CoreGatewayTypes.h"
- #endif
-
- #ifndef __EVENTCOUNTDOWN__
- #include "EventCountdown.h"
- #endif
-
- #ifndef __HALFGATEWAY__
- #include "HalfGateway.h"
- #endif
-
- #ifndef __RAMTUPLEDATABASE__
- #include "RamTupleDatabase.h"
- #endif
-
- #ifndef __OCEOBJECTS__
- #include "OCEObjects.h"
- #endif
-
- #ifndef __THREADCLASSES__
- #include "ThreadClasses.h"
- #endif
-
- /***********************************|****************************************/
-
- class TVirtualMacFile;
- class TVirtualFolder;
-
- /***********************************|****************************************/
-
- class TRLIList;
-
- /***********************************|****************************************/
-
- class T2020HalfGateway : public THalfGateway
- {
- public:
-
- T2020HalfGateway();
- virtual ~T2020HalfGateway ();
-
- public:
- //
- // HALF-GATEWAY SETUP METHODS
- //
- virtual Boolean Setup (TMailGateway& gateway, short vRefNum, long dirID, const char* gatewayName);
-
- //
- // HALF-GATEWAY RECOVERY METHODS
- //
- virtual Boolean BeginRecoveryPhase(void);
- virtual Boolean IsRecoveryDone(void);
- virtual Boolean FinishRecoveryPhase(void);
-
- virtual Boolean ResendLetter (TLetter* letter);
- virtual Boolean RereceiveLetter (TLetter* letter);
-
- //
- // HALF-GATEWAY OPERATION METHODS
- //
- virtual Boolean Run (void);
- virtual Boolean SendLetter(TLetter *letter);
- virtual Boolean ReceiveLetter(TLetter* letter);
-
- virtual Boolean PrepareToShutDown(long inHowManySeconds);
- virtual Boolean IsHalfGatewayShuttingDown(void);
- virtual Boolean IsHalfGatewayReadyToShutDown(void);
- virtual Boolean CancelHalfGatewayShutdown (void);
- virtual Boolean ShutDown(void);
- virtual Boolean GetStatusStr ( Str255& statusStr ) const;
-
- virtual Boolean GetStatusItem(const ATupleKey& key, ADataItem& buffer);
- virtual Boolean SetStatusItem(const ATupleKey& key, const ADataItem& buffer);
-
- virtual Boolean HandleMonitoringEvent ( const ADataItem& event );
-
- //
- // 2020 HALF-GATEWAY SPECIFIC METHODS
- // ==================================
- //
-
- // Create all of the 'normal' execution threads for this half gateway.
- protected: void CreateThreads ( void );
-
- // This method becomes the '2Scn' thread. It periodically checks if there is a letter
- // available from 2020 which our gateway needs to process. If there is, it creates a
- // T2020Letter object for the letter, and then sends this letter to the mail gateway.
- public:
- void Scan2020ForOutgoingLetters(void);
-
- // This method becomes the '2Put' thread. It periodically checks if there are any items
- // in the fReceivedLetters list. If there are items in there, it calls the
- // DoReceiveALetter() method with each item.
- void PutReceivedLettersInto2020(void);
-
- // This method becomes the '2Sen' thread. It periodically checks the list fLettersFromOCEToBeSent,
- // and does a SendLetter for each one.
- void SendOCELettersToMailGateway(void);
-
- // This method becomes the '2Rec' thread. It periodically checks the list fReportsFromOCEToBeProcessed,
- // and does a HandleRecipientReport() for each one.
- void ProcessLetterRecipientReports(void);
-
- // This method becomes the '2Per' thread. It handles periodic tasks.
- protected: void PeriodicTasks();
- friend void T2020DoPeriodicTasksWrapper(unsigned long g, unsigned long h);
-
-
- // This method updates the fAvailableDirectories field. This list contains the
- // names, discriminators, and flags for all of the available 2020 directories.
- public: void UpdateDatabaseOfAvailable2020Directories();
-
- virtual Boolean UpdateExtendedDirectoriesList ( );
- virtual TForeignDNode* GetExtendedDirectoryForeignDNode ( OSType directoryType ) const;
-
- // This method handles the recipient reports which we get from 2020.
- Boolean HandleRecipientReport (T2020Letter* report);
-
-
- // This method puts a report for the given letter into OCE. It return true if
- // there were no problems, false otherwise.
- public: Boolean CreateRecipientReportForLetter(T2020Letter* letter);
-
- //
- // These methods support path names to be converted to dNodeNumbers, and vice versa.
- //
- public: Boolean FindDNodeForPathName(const TPathName& pathName, const TDirectory& directory, DNodeNum& dNodeNumber);
- public: Boolean FindPathNameForDNode(const DNodeNum& dNodeNumber, const TDirectory& directory, TPathName& pathName);
-
- // Get the AOCE directory system that we're attached to.
- public: virtual const TDirectory & GetAOCEDirectory () const;
-
- /***********************************|****************************************/
- //
- // Finding ADAS addresses
- //
- public: unsigned long FindADASAddresses (const TRString& recordName, const TRString& recordType, const DNodeNum clusterToSearch, TRecordID& resultAddress, unsigned long maxToFind = 10);
- unsigned long FindADASAddresses (const TRString& recordName, const TRString& recordType, const TRLI& clusterToSearch, TRecordID& resultAddress, unsigned long maxToFind = 10);
- unsigned long FindADASAddresses (const TRString& recordName, const TRString& recordType, TRecordID& resultAddress, unsigned long maxToFind = 10);
- unsigned long FindADASAddresses (const TCreationID& cid, const DNodeNum dNode, TRecordID& result);
- unsigned long FindADASAddresses (const TCreationID& cid, const DNodeNum dNode, const TDirectory& directory, TRecordID& result);
-
-
- protected: TRLIList* GetChildClusters ();
- TRLIList* GetChildClusters (const TRLI& parentCluster);
-
-
-
- /***********************************|****************************************/
- //
- // Finding, examing, and creating ADAS Records
- //
- public: Boolean GetADASAttributeValue ( const TRecordID& whichRecord,
- const TRString& attributeType,
- void * dataPtr, unsigned long dataSize );
- Boolean GetADASAttributeValue ( const TRecordID& whichRecord,
- const TRString& attributeType,
- ADataItem& value );
-
- protected:
- virtual void ResetStatistics ( );
- virtual void SetStatusStr ( Str255 statusStr );
-
- //
- // RECOVERY PHASE METHODS
- // ======================
- //
- // This method becomes the '2rsc' thread, which is only used during the recovery phase.
- // It scans OCE and re-sends any letter which is not 'done', in order to insure that
- // mail is not lost if the gateway crashes or is shut down.
- protected:
- void ResendLettersAtStartup();
- friend void DoResendLettersAtStartupWrapper(unsigned long g, unsigned long h);
-
- //
- // High-Level Events: The 'main event' loop must call these if a high-level event
- // with type kMailAppleMailCreator type occurs.
- public:
- Boolean HandleAppleMailHighLevelEvent ( const EventRecord& event );
-
- protected: // These get called by HandleAppleMailHighLevelEvent
- OSErr AppleEventMsgPendingEvent ( void );
- OSErr AppleEventAdminEvent ( void );
-
-
- protected:
- /***********************************|****************************************/
- OSErr CreateAOCEForwarderRecord ( );
- void SetupServerIdentity ( );
- void SetupServerQueueID ( );
- Boolean SetupMailRoutingInformation ( );
-
- public:
- AuthIdentity GetForwarderIdentity () const;
- long GetServerQueueID () const;
-
- AddrBlock GetAOCEServerHint ( ) const;
-
- typedef OSErr DirToolboxCallFunc ( DirParamBlock* pb );
- OSErr AOCEMakeDirToolboxCallWithRetry ( DirToolboxCallFunc dirToolboxCall, DirParamBlock* pb );
-
- typedef OSErr AuthToolboxCallFunc ( AuthParamBlock* pb );
- OSErr AOCEMakeAuthToolboxCallWithRetry ( AuthToolboxCallFunc authToolboxCall, AuthParamBlock* pb );
-
- // These all are called as part of the process of putting a letter into 2020
- protected:
- void ReceiveALetter (TLetter *letter);
-
- MailMsgRef CreateAOCELetter () const;
- void PutBLJLetterIDIntoLetter ( const MailMsgRef letterRef, short attrID, const BLJLetterID& id) const;
- void SubmitAOCELetter ( MailMsgRef& letterRef ) const;
- void AbortAOCELetter ( MailMsgRef& letterRef ) const;
-
- void PutAttributeIntoLetter (long letterRef, short attrID, void *data, short dataSize) const;
-
- Boolean PutRecipientIntoLetter (long letterRef, short attrID, const OCERecipient& oceRecipient, Boolean responsible);
- Boolean PutRecipientIntoLetter (long letterRef, short attrID, const TRecordID& recordID, Boolean responsible);
- Boolean PutRecipientIntoLetter (long letterRef, short attrID, TRecipient* recipient, Boolean responsible);
-
- Boolean PutStandardRecipientIntoLetter (long letterRef, short attrID, TRecipient* recipient, Boolean responsible );
- Boolean PutExternalRecipientIntoLetter (long letterRef, short attrID, TRecipient* recipient, Boolean responsible );
-
- void PutIndicationsIntoLetter(long letterRef, TLetter* receivedLetter);
- void PutContentIntoLetter (long letterRef, TLetter *receivedLetter);
- void PutBlockIntoLetter(long letterRef, void* blockData, unsigned long blockSize);
- void PutPictureIntoLetter (long letterRef, TLetter* receivedLetter);
- void PutEnclosuresFolderIntoLetter (long letterRef, TVirtualFolder *enclosuresFolder);
- void PutVirtualMacFileIntoEnclosures (long letterRef, long dirID, TVirtualMacFile* macFile);
- void PutVFolderIntoLetterEnclosures (long letterRef, long parentDirID, TVirtualFolder* folder, long& nextDirID);
-
- #if debug
- public:
- #else
- protected:
- #endif
- short fWorkingVRefNum; // the vRefNum and dirID of the 'BovineWorking'
- long fWorkingDirID; // folder we should store all of our info into.
-
- Boolean fShuttingDown; // this is set to true when the gateway is trying
-
- TDirectory fAOCEDirectoryWeServe;
-
- OSType fOurGatewayMailExtensionType;
- TRLI fOurGatewayMailRLI;
- TDirectory fOurGatewayMailDirectory;
-
- TRecordID fOurForwarderRecord;
-
- AuthIdentity fForwarderIdentity; // this is the 'validated' identity for this server
- long fServerQueueID;
- long fEnumerateStartSeqNum; // this is the 'next' letter sequence number, which we use
-
- Boolean fInRecoveryPhase;
- TThread* fRecoveryPhaseScanThread;
- TThread* fRunThreadH;
- TThread* fScan2020ThreadH;
- TThread* fPutLettersInto2020ThreadH;
- TThread* fSendLettersFromOCEToMailGatewayThreadH;
- TThread* fProcessLetterRecipientReportsThreadH;
- TThread* fPeriodicTasksThread;
-
- // This tuple database contains all of the directories, their discriminators, et al.,
- // which are connected to this 2020 system.
- TRamTupleDatabase fAvailable2020Directories;
-
- unsigned long fNextTimeToUpdateListOfKnownExtendedDirectories;
- TSortedForeignDNodeList fKnownExtendedDirectories;
-
- TEventCountdown fLettersWaitingForRecipientReportsCountdownTimer;
-
- AddrBlock fAOCEServerHint;
-
- TLetterQueue fReceivedLetters;
- T2020LetterQueue fLettersFromOCEToBeSent;
- T2020LetterQueue fReportsFromOCEToBeProcessed;
- TSharedLetterList fLettersWaitingForRecipientReports;
-
-
- //
- // STATUS ITEMS
- // ============
- //
- Boolean fDoNotSendLetters;
- Boolean fDoNotReceiveLetters;
-
- unsigned long fLettersSentToAOCE;
- unsigned long fLettersReceivedFromAOCE;
- unsigned long fTotalKOfContentSentToAOCE;
- unsigned long fTotalKOfEnclosuresSentToAOCE;
-
- long fAOCEToolboxVersion;
- long fAOCEMailServerVersion;
-
- TRString fOurGatewayDescription;
-
- Str255 fStatusStr;
- };
-
- // This struct is used to store information about a letter when
- // we put the letter into OCE. Later, all letter reports for this
- // letter will include this struct in the letter report; and our
- // halfgateway thes uses this info to find the original letter in
- // the fLettersWaitingForRecipientReports list.
-
- typedef struct MyGWYIBlockRecord {
- unsigned long version;
- BLJLetterID letterID;
- } MyGWYIBlockRecord;
-
- const unsigned long kMyGWYIBlockRecordVersion = 1;
-
- /***********************************|****************************************/
-
- inline AuthIdentity T2020HalfGateway::GetForwarderIdentity () const
- {
- #if debug
- if ( fForwarderIdentity == 0 )
- keithDB ( "T2020HalfGateway::GetForwarderIdentity, WARNING! Getting 0 identity." );
- #endif
-
- return fForwarderIdentity;
- }
-
- /***********************************|****************************************/
-
- inline long T2020HalfGateway::GetServerQueueID () const
- {
- #if debug
- if ( fServerQueueID == 0 )
- keithDB ( "T2020HalfGateway::GetServerQueueID, WARNING! Getting 0 queueID." );
- #endif
-
- return fServerQueueID;
- }
-
- /***********************************|****************************************/
-
- inline const TDirectory & T2020HalfGateway::GetAOCEDirectory () const
- {
- return fAOCEDirectoryWeServe;
- }
-
- /***********************************|****************************************/
-
- inline AddrBlock T2020HalfGateway::GetAOCEServerHint ( ) const
- {
- return fAOCEServerHint;
- }
-
- /***********************************|****************************************/
-
- typedef OSErr DirToolboxCallFunc ( DirParamBlock* pb );
- typedef OSErr AuthToolboxCallFunc ( AuthParamBlock* pb );
-
- /***********************************|****************************************/
-
- OSErr AOCEMakeDirToolboxCallWithRetry ( DirToolboxCallFunc dirToolboxCall, DirParamBlock* pb );
- OSErr AOCEMakeAuthToolboxCallWithRetry ( AuthToolboxCallFunc authToolboxCall, AuthParamBlock* pb );
-
- /***********************************|****************************************/
-
- #endif // __2020HALFGATEWAY__
-